#include <iostream>
#include <memory>
#include <string>
#include "epollServer.hpp"
#include "Log.hpp"
#include "Err.hpp"

using namespace std;

void Usage(const char *proc)
{
    cout << "=============================" << endl;
    cout << "Usage:" << endl;
    cout << "\t" << proc << " port" << endl;
    cout << "=============================" << endl;
}

std::string echoServer(std::string request)
{
    // 引入协议
    request += " [EpollServer Respond]\n";
    return request;
}

int main(int argc, char *args[])
{
    if (argc != 2)
    {
        Usage(args[0]);
        logMessage(Warning, "Parameters are not used correctly");
        exit(USER_ERR);
    }

    uint16_t port = stoi(args[1]);
    shared_ptr<Yohifo::EpollServer> psvr(new Yohifo::EpollServer(echoServer, port));
    psvr->InitServer();
    psvr->Dispatcher();

    return 0;
}